#include "CCircle.h"
#include "stdio.h"
#include "2D/Wall2D.h"
void CCircle::Render()
{
	VideoDriver::GetInstance()->SetColor(0xFF0000);
	VideoDriver::GetInstance()->DrawCircle(m_vPosition.x, m_vPosition.y, m_fRadius);
	//Update();
}
void CCircle::UpdateWidthBound(CBound bound)
{
	m_vVelocity += m_vG;
	m_vVelocity.y -= (double)m_fMass/1000.0f;
	m_vPosition += m_vVelocity;

	if(m_eCollideStatus == E_BOTTOM)
	{
		m_vVelocity = m_vVelocity.Reflect(bound.m_wBottom.Normal());
	}else if(m_eCollideStatus == E_TOP)
	{
		m_vVelocity = m_vVelocity.Reflect(bound.m_wTop.Normal());
	}else if(m_eCollideStatus == E_LEFT)
	{
		m_vVelocity = m_vVelocity.Reflect(bound.m_wLeft.Normal());
	}else if(m_eCollideStatus == E_RIGHT)
	{
		m_vVelocity = m_vVelocity.Reflect(bound.m_wRight.Normal());
	}
}
void CCircle::TouchActionDrag(int x, int y)
{
	if(!s_bPressed)
		return;
	s_bDragged = true;
	Vector2D v = Vector2D((double)x, (double)y);
	m_vPosition = v;
}
void CCircle::TouchActionDown(int x, int y)
{
	s_bDragged = false;
	Vector2D v = Vector2D((double)x, (double)y);
	if(PointIntoCircle(v))
		s_bPressed = true;
	else
		s_bPressed = false;
}
void CCircle::TouchActionUp(int x, int y)
{
	s_bDragged = false;
	s_bPressed = false;
}
void CCircle::CheckCollisionWithBound(CBound bound)
{
	if(m_vPosition.y + m_fRadius >= SCREEN_H)
	{
		m_eCollideStatus = E_BOTTOM;
	}
	else if(m_vPosition.y - m_fRadius <= 0)
	{
		// m_vVelocity = m_vVelocity.Reflect(bound.m_wTop.Normal());
		m_eCollideStatus = E_TOP;
	}
	else if(m_vPosition.x + m_fRadius >= SCREEN_W)
	{
		//m_vVelocity = m_vVelocity.Reflect(bound.m_wRight.Normal());
		m_eCollideStatus = E_RIGHT;
	}
	else if(m_vPosition.x - m_fRadius <= 0)
	{
		//m_vVelocity = m_vVelocity.Reflect(bound.m_wLeft.Normal());
		m_eCollideStatus = E_LEFT;
	}
}